//加载页面
$(function(){
    list=[
        "广州市",
        "深圳市",
        "佛山市",
        "潮州市"
    ]
    function getdata(index){
        $.ajax({
            url:`http://api.tianapi.com/tianqi/index?key=cbcd0d501c4db9c5fc7bf3a51373d7b5&city=${list[index]}`,
            type:"GET",
            data:{"num":10},
            success:function(data){
                var html="";
                $.each(data.newslist,function(index,item){
                    html+=`
                    <div class="card">
                        <div class="left"><img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.ixintu.com%2Fdownload%2Fjpg%2F202005%2F31bc5c2a0b64bb7062b9b86c527e9b14_610_610.jpg%21con&refer=http%3A%2F%2Fimg.ixintu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1658131452&t=2e1398bdc3ae89e5018464dd36041776" alt=""></div>
                        <div class="right">
                            <span>${item.date}</span>
                            <span>${item.week}</span>
                            <span>${item.weather}</span><br>
                            <span>实时温度：${item.real}</span>
                            <span>最低温度：${item.lowest}</span>
                            <span>最高温度：${item.highest}</span><br>
                            <span class="tips">${item.tips}</span>
                        </div>
                    </div>`
                })
                //接口返回的数据渲染至页面
                if(pag==1)
                {
                    $(".neir").html(html)
                }
                else{
                    $(".neir").append(html)
                }
                //点击跳转新闻链接
                // $(".card").click(function(){
                //     window.location.href=$(this).data("url");
                // })
            },
            error:function(){
                alert("出错了")
            },
            dataType:"json"
        });
    }
    //tab栏点击
$(".tab li").click(function(){
    $(this).attr("class","curr").siblings().attr("class","");
    pag=1;
    getdata($(this).index());
})
//新闻数据请求
pag=1;
getdata(1);
//滑动到底部刷新
// $(window).scroll(function(){
//     if($(document).scrollTop()>=$(document).height()-$(window).height()){
//         pag++;
//         getdata($(".curr").index());
//     }
// });
})